clear
clear matrix
clear mata
program drop _all
set more off
set emptycells drop
set maxvar 100000
tempfile main diagnostics

cd "<directory>"



*The code in this .do file reads in the dataset created in Data Cleaning Step 2.do and runs the code for Figures 3 and 4;
u final_dataset,clear
tempfile mainforgraph
sa `mainforgraph',replace
sa `main',replace
keep if yearmonth>=572 & yearmonth<=620
drop if propid==.
keep dosname masterloanidtrepp post transfer origyear orig_ltv securwac securocc orig_dscrnoi2 transfer dpopp_indic_base dpopp_indic dpopp_indic2 dpopp_indic3 transfer_fullpay2 propid myproptype myss msa transfer_nodlq2 ssid dpopp_indic_basedate treated_wl treated_dlq treated_dlqwl evertransfer_pre evertransfer dspp0_5t8 dspp0_4t7 dspp0_6t9 dspp0_7t10 distyear distmonth distyq distym ltv occrate dscrnoi age balratio remterm
sa `diagnostics',replace



*	Figure 3:;
u `diagnostics',clear
collapse (mean) transfer (max) distyear distmonth,by(distym treated_wl)
keep transfer distym treated_wl distyear distmonth
reshape wide transfer,i(distym) j(treated_wl)
label var transfer0 "Control (watchlisted pre-2009)"
label var transfer1 "Treated (not watchlisted pre-2009)"
gen distym2=ym(distyear,distmonth)
form distym2 %tm
label var distym2 "Month"
scatter transfer0 transfer1 distym2, xline(596) xlabel(572(3)620, labsize(small) angle(45)) ytitle("Transfer frequency") msymbol(Oh D) mcolor(black black) legend(order(1 "Control (Watchlist pre-Aug 2009)" 2 "Treatment (not Watchlist pre-Aug 2009)") )
graph save "Graph" "<directory>",replace
graph export "<directory>", as(png) name("Graph") replace



*Figure 4:;
u `diagnostics',clear
collapse (mean) transfer (max) distyear distmonth,by(distym treated_dlq)
keep transfer distym treated_dlq distyear distmonth
reshape wide transfer,i(distym) j(treated_dlq)
label var transfer0 "Control (DLQ pre-2009)"
label var transfer1 "Treated (not DLQ pre-2009)"
gen distym2=ym(distyear,distmonth)
form distym2 %tm
label var distym2 "Month"
scatter transfer0 transfer1 distym2, xline(596) xlabel(572(3)620, labsize(small) angle(45)) ytitle("Transfer frequency") msymbol(Oh D) mcolor(black black) legend(order(1 "Control (DLQ pre-Aug 2009)" 2 "Treatment (not DLQ pre-Aug 2009)"))
graph save "Graph" "<directory>",replace
graph export "<directory>", as(png) name("Graph") replace